package org.jsbd.boss.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.dao.IBookMarkDao;
import org.jsbd.boss.dao.IBookMarkFailCountDao;
import org.jsbd.boss.domian.BookMark;
import org.jsbd.boss.domian.BookMarkFailCount;
import org.jsbd.boss.service.IBookMarkService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("bookMarkService")
public class BookMarkServiceImpl implements IBookMarkService {

	@Autowired
	private IBookMarkDao bookMarkDao;
	@Autowired
	private IBookMarkFailCountDao bookMarkFailCountDao;

	@Override
	public void save(BookMark bookMark) {
		bookMarkDao.save(bookMark);
	}

	@Override
	public void save(List<BookMark> list) {
		bookMarkDao.save(list);
	}

	@Override
	public int update(BookMark bookMark) {
		return bookMarkDao.update(bookMark);
	}

	@Override
	public BookMark get(BookMark bookMark) {
		return bookMarkDao.get(bookMark);
	}

	@Override
	public BookMark getById(Integer id) {
		return bookMarkDao.getById(id);
	}

	@Override
	public List<BookMark> getList(BookMark bookMark){
		return bookMarkDao.getList(bookMark);
	}
	
	@Override
	public Map<String, Object> getListPage(DataGridModel page, BookMark bookMark) {
		
		bookMark = (bookMark == null ? new BookMark() : bookMark);
		bookMark.setPageInfo(page);
		Map<String, Object> results = new HashMap<String, Object>();
		results.put("total", bookMarkDao.getListPageCount(bookMark));
		
		List<BookMark> list = (List<BookMark>) bookMarkDao.getList(bookMark);
		for (BookMark bk : list) {
			bk.setCreateDate(org.jsbd.boss.util.DateUtil.getYmdhmsDateStr(bk.getCreateTime()));
			bk.setModifyDate(org.jsbd.boss.util.DateUtil.getYmdhmsDateStr(bk.getModifyTime()));
		}
		results.put("rows", list);
		return results;
	}
	
	@Override
	public void delete(List<Integer> ids) {
		bookMarkDao.delete(ids);
	}

	@Override
	public String getApkNameByMark(String mark) {
		return bookMarkDao.getApkNameByMark(mark);
	}

	@Override
	public Map<String, Object> getFailCountListPage(DataGridModel page, BookMarkFailCount bookMarkFailCount) {
		
		bookMarkFailCount = (bookMarkFailCount == null ? new BookMarkFailCount() : bookMarkFailCount);
		bookMarkFailCount.setPageInfo(page);
		Map<String, Object> results = new HashMap<String, Object>();
		results.put("total", bookMarkFailCountDao.getListPageCount(bookMarkFailCount));
		
		List<BookMarkFailCount> list = bookMarkFailCountDao.getList(bookMarkFailCount);
		for (BookMarkFailCount bk : list) {
			bk.setCreateDate(org.jsbd.boss.util.DateUtil.getYmdhmsDateStr(bk.getCreateTime()));
			bk.setModifyDate(org.jsbd.boss.util.DateUtil.getYmdhmsDateStr(bk.getModifyTime()));
		}
		results.put("rows", list);
		return results;
	}

	@Override
	public List<BookMarkFailCount> getFailCountList(BookMarkFailCount bookMarkFailCount) {
		List<BookMarkFailCount> list = bookMarkFailCountDao.getList(bookMarkFailCount);
		return list;
	}
}
